#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 - 2013 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1

#include <Macros.h>
#include <ValueHelpers.h>
#include <Settings.h>

#pragma unmanaged 
#include <ql\discretizedasset.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;
using namespace Cephei::Core;
using namespace PLATFORM::Collections;

using namespace Cephei::QL::Math;
#undef HANDLE
#define ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IDiscretizedAsset
	public ref class CDiscretizedAsset  : 
            public Cephei::QL::IDiscretizedAsset
	{
	protected: 
		boost::shared_ptr<QuantLib::DiscretizedAsset>* _ppDiscretizedAsset;
        boost::detail::spinlock* _pSpinlock;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::DiscretizedAsset>* _phDiscretizedAsset;
#endif
		Object^ _DiscretizedAssetOwner;     // reference to object that manages the storage for this object
	internal:
        CDiscretizedAsset (boost::shared_ptr<QuantLib::DiscretizedAsset>& childNative, Object^ owner);
        CDiscretizedAsset (QuantLib::DiscretizedAsset& childNative, Object^ owner);
        CDiscretizedAsset (CDiscretizedAsset^ copy);
        CDiscretizedAsset (PLATFORM::Type^ t);
#ifdef STRUCT
        CDiscretizedAsset (QuantLib::DiscretizedAsset childNative);
#endif       
#ifdef HANDLE
		CDiscretizedAsset (QuantLib::Handle<QuantLib::DiscretizedAsset>& childNative, Object^ owner);
		CDiscretizedAsset (QuantLib::Handle<QuantLib::DiscretizedAsset> childNative);
#endif
		virtual ~CDiscretizedAsset ();
		!CDiscretizedAsset ();

	internal:
		QuantLib::DiscretizedAsset& GetReference ();
		boost::shared_ptr<QuantLib::DiscretizedAsset>& GetShared ();
		QuantLib::DiscretizedAsset* GetPointer ();
        void SetDiscretizedAsset (boost::shared_ptr<QuantLib::DiscretizedAsset> native)
        {
            if (_ppDiscretizedAsset != NULL)
                delete _ppDiscretizedAsset;
            _ppDiscretizedAsset = new boost::shared_ptr<QuantLib::DiscretizedAsset> (native);
            
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::DiscretizedAsset>& GetHandle ();
#endif
		virtual bool HasNative () ;
		void Lock ()
		{
			if (Cephei::QL::Settings::_ReferenceLocking)
    			_pSpinlock->lock ();
		}
		void Unlock ()
		{
			_pSpinlock->unlock ();
		}
    public:
        property Cephei::QL::IDiscretizedAsset^ AdjustValues 
        {
		    virtual Cephei::QL::IDiscretizedAsset^ get () ;
        }
		virtual Cephei::QL::IDiscretizedAsset^ Initialize (Cephei::QL::ILattice^ prm1, Double t) ;
        property Cephei::Core::IVector<Double>^ MandatoryTimes 
        {
		    virtual Cephei::Core::IVector<Double>^ get () ;
        }
        property Cephei::QL::ILattice^ Method 
        {
		    virtual Cephei::QL::ILattice^ get () ;
        }
		virtual Cephei::QL::IDiscretizedAsset^ PartialRollback (Double to) ;
        property Cephei::QL::IDiscretizedAsset^ PostAdjustValues 
        {
		    virtual Cephei::QL::IDiscretizedAsset^ get () ;
        }
        property Cephei::QL::IDiscretizedAsset^ PreAdjustValues 
        {
		    virtual Cephei::QL::IDiscretizedAsset^ get () ;
        }
        property Double PresentValue 
        {
		    virtual Double get () ;
        }
		virtual Cephei::QL::IDiscretizedAsset^ Reset (UInt64 size) ;
		virtual Cephei::QL::IDiscretizedAsset^ Rollback (Double to) ;
        property Double Time 
        {
		    virtual Double get () ;
        }
        property Cephei::QL::Math::IArray^ Values 
        {
		    virtual Cephei::QL::Math::IArray^ get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
//z	[FactoryFor(Core::Generic::ICoCell<Cephei::QL::IDiscretizedAsset^>::typeid)]
	[FactoryFor(Cephei::QL::IDiscretizedAsset::typeid)]
	[FactoryFor(Cephei::QL::IDiscretizedAsset_Factory::typeid)]
	public ref class CDiscretizedAsset_Factory sealed : public IDiscretizedAsset_Factory
	{
	public:
    };
   
/*Cephei*/ } /*QL */}
